// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   AlterField.java

package com.oa.workflow;

import com.oa.database.DataConn;
import java.io.PrintStream;
import java.sql.*;

public class AlterField
{

    private DataConn dataConn;
    private Connection conn;
    private Statement stmt;
    private String sql;
    private String str_error;

    public AlterField()
    {
        dataConn = null;
        conn = null;
        stmt = null;
        sql = null;
        str_error = null;
    }

    public AlterField(DataConn dataConnection)
    {
        dataConn = null;
        conn = null;
        stmt = null;
        sql = null;
        str_error = null;
        dataConn = dataConnection;
        conn = dataConn.getConnection();
    }

    public String getErrorMessage()
    {
        return str_error;
    }

    public boolean addField(String sTable, String sField)
    {
        try
        {
            sql = " ALTER TABLE " + sTable + " ADD " + sField;
            stmt = conn.createStatement();
            stmt.execute(sql);
            stmt.close();
        }
        catch(SQLException e)
        {
            str_error = e.getMessage();
            return false;
        }
        return true;
    }

    public boolean updateField(String sTable, String sField)
    {
        try
        {
            sql = " ALTER TABLE " + sTable + " ALTER COLUMN " + sField;
            stmt = conn.createStatement();
            stmt.execute(sql);
            stmt.close();
        }
        catch(SQLException e)
        {
            str_error = e.getMessage();
            return false;
        }
        return true;
    }

    public boolean deleteField(String sTable, String sField)
    {
        try
        {
            sql = " ALTER TABLE " + sTable + " DROP COLUMN " + sField;
            stmt = conn.createStatement();
            stmt.execute(sql);
            stmt.close();
        }
        catch(SQLException e)
        {
            str_error = e.getMessage();
            return false;
        }
        return true;
    }

    public boolean deleteTable(String sTable)
    {
        try
        {
            sql = " DROP TABLE " + sTable;
            stmt = conn.createStatement();
            stmt.execute(sql);
            stmt.close();
        }
        catch(SQLException e)
        {
            str_error = e.getMessage();
            return false;
        }
        return true;
    }

    public boolean createTable(String sTable, String sField)
    {
        try
        {
            String strSQL = "";
            Connection conn = dataConn.getConnection();
            Statement stmt = conn.createStatement();
            strSQL = " drop table [dbo].[" + sTable + "]";
            try
            {
                stmt.execute(strSQL);
            }
            catch(Exception exception) { }
            strSQL = "CREATE TABLE [dbo].[" + sTable + "] (" + "[" + sField + "] [int] IDENTITY (1, 1) NOT NULL ) ON [PRIMARY]";
            stmt.executeUpdate(strSQL);
            stmt.close();
        }
        catch(Exception e)
        {
            str_error = e.getMessage();
            System.out.println("---" + e);
        }
        return true;
    }

    public static void main(String args[])
    {
        DataConn dataConn = new DataConn();
        AlterField alterField = new AlterField(dataConn);
        String sTable = "aa";
        String sField = "kk";
        alterField.createTable(sTable, sField);
    }
}
